//
//  BK_EXChangeVoucher_Bottom_View.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/3/23.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_EXChangeVoucher_Bottom_View.h"
#import "BKMainCommon.h"
#import "BKExchangeGoodsModel.h"
#import "BKCouponInfoModel.h"

@interface BK_EXChangeVoucher_Bottom_View()

@property (nonatomic, strong) UIButton *exchangeScoresButton;

@property (nonatomic, strong) UIView *compoundView;
@end
@implementation BK_EXChangeVoucher_Bottom_View

- (UIButton *)exchangeScoresButton {
    
    if (!_exchangeScoresButton) {
        _exchangeScoresButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_exchangeScoresButton addTarget:self action:@selector(exchangeScoresAction:) forControlEvents:UIControlEventTouchUpInside];
        [_exchangeScoresButton setTitle:@"立即兑换" forState:UIControlStateNormal];
        _exchangeScoresButton.titleLabel.textColor = [UIColor whiteColor];
        _exchangeScoresButton.backgroundColor = RGB(0, 186, 156);
        _exchangeScoresButton.titleLabel.font = [Common systemFontOfSize:17];
        [self addSubview:_exchangeScoresButton];
        [_exchangeScoresButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top);
            make.bottom.mas_equalTo(self.mas_bottom);
            make.left.mas_equalTo(self.mas_left);
            make.right.mas_equalTo(self.mas_right);
        }];
    }
    return _exchangeScoresButton;
}
- (UIView *)compoundView {
    
    if (!_compoundView) {
        _compoundView = [[UIView alloc] init];
        [self addSubview:_compoundView];
        [_compoundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top);
            make.bottom.mas_equalTo(self.mas_bottom);
            make.left.mas_equalTo(self.mas_left);
            make.right.mas_equalTo(self.mas_right);
        }];
    }
    return _compoundView;
}
- (instancetype)init {
    
    self = [super init];
    if (self) {
        
        UIButton *scoresUnenough = [UIButton buttonWithType:UIButtonTypeCustom];
        [scoresUnenough setTitle:@"积分不足" forState:UIControlStateNormal];
        [scoresUnenough addTarget:self action:@selector(scoresUnenoughAction:) forControlEvents:UIControlEventTouchUpInside];
        scoresUnenough.titleLabel.font = [Common systemFontOfSize:17];
        scoresUnenough.titleLabel.textColor = [UIColor whiteColor];
        scoresUnenough.backgroundColor = RGB(184, 184, 184);
        [self.compoundView addSubview:scoresUnenough];
        [scoresUnenough mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top);
            make.bottom.mas_equalTo(self.mas_bottom);
            make.left.mas_equalTo(self.mas_left);
            //            make.width.mas_equalTo(478.0f/750.0f*ScreenWidth);
            make.width.mas_equalTo(2.0f/5.0f*ScreenWidth);
        }];
        
        UIButton *makeScores = [UIButton buttonWithType:UIButtonTypeCustom];
        [makeScores setTitle:@"立即赚分" forState:UIControlStateNormal];
        [makeScores addTarget:self action:@selector(makeScroesAction:) forControlEvents:UIControlEventTouchUpInside];
        makeScores.titleLabel.font = [Common systemFontOfSize:17];
        makeScores.titleLabel.textColor = [UIColor whiteColor];
        makeScores.backgroundColor = RGB(0, 186, 156);
        [self.compoundView addSubview:makeScores];
        [makeScores mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top);
            make.bottom.mas_equalTo(self.mas_bottom);
            make.right.mas_equalTo(self.mas_right);
            make.left.mas_equalTo(scoresUnenough.mas_right);
        }];
        
    }
    return self;
}
//是否可兑换：1立即兑换；0立即赚分;2今日已兑换"
- (void)updateBottomView:(BKExchangeGoodsModel *)model {
    
    if ([model.exchangeFlag isEqualToString:@"0"]) {
        
        self.exchangeScoresButton.hidden = YES;
        self.compoundView.hidden = NO;
    }else {
        self.exchangeScoresButton.hidden = NO;
        [self.exchangeScoresButton setTitle:model.exchangeBtnText forState:UIControlStateNormal];
        self.compoundView.hidden = YES;
        if ([model.exchangeFlag isEqualToString:@"1"]) {
            self.exchangeScoresButton.userInteractionEnabled = YES;
        }else {
            self.exchangeScoresButton.userInteractionEnabled = NO;
            self.exchangeScoresButton.backgroundColor = RGB(184, 184, 184);
        }
    }
}
/*可否兑换 0可兑换，1券已经被兑完，2今日已兑换，3积分不够"*/
-(void)UpdateBottomView:(BKCouponInfoModel*)model{
    NSString *type = [NSString stringWithFormat:@"%@",model.exchangeErrorType];
    if ([type isEqualToString:@"3"]) {
        self.exchangeScoresButton.hidden = YES;
        self.compoundView.hidden = NO;
        
    }else{
        self.exchangeScoresButton.hidden = NO;
        self.compoundView.hidden = YES;
        if ([type isEqualToString:@"0"]) {
            [self.exchangeScoresButton setTitle:@"立即兑换" forState:UIControlStateNormal];
            self.exchangeScoresButton.userInteractionEnabled = YES;
        }else if ([type isEqualToString:@"1"]){
            [self.exchangeScoresButton setTitle:@"券已经被兑完" forState:UIControlStateNormal];
            self.exchangeScoresButton.userInteractionEnabled = NO;
            self.exchangeScoresButton.backgroundColor = RGB(184, 184, 184);
        }else{
            [self.exchangeScoresButton setTitle:@"今日已兑换" forState:UIControlStateNormal];
            self.exchangeScoresButton.userInteractionEnabled = NO;
            self.exchangeScoresButton.backgroundColor = RGB(184, 184, 184);
        }
    }
}

- (void)exchangeScoresAction:(UIButton *)sender {
    
    if ([self.deleaget respondsToSelector:@selector(exchangeScoresButtonAction:)]) {
        [self.deleaget exchangeScoresButtonAction:sender];
    }
}

- (void)scoresUnenoughAction:(UIButton *)sender {
    
    if ([self.deleaget respondsToSelector:@selector(scoresUnenoughButtonAction:)]) {
        [self.deleaget scoresUnenoughButtonAction:sender];
    }
}
- (void)makeScroesAction:(UIButton *)sender {
    
    if ([self.deleaget respondsToSelector:@selector(makeScoresButtonAction:)]) {
        [self.deleaget makeScoresButtonAction:sender];
    }
}

@end






























